<!doctype html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8" />
    <title>混淆器页面</title>
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <link rel="stylesheet" href="./css/element.css" />
    <link rel="stylesheet" href="./css/index.css" />
</head>

<body>
    <div id="app">
        <!-- 仓库地址显示 -->
        <el-row style="margin-bottom: 10px;">
            <el-col :span="24" style="text-align: left;">
                <div style="font-size: 14px; color: #666;">
                    🧭 项目仓库：
                    <el-link href="https://gitee.com/eobard721/obfuscator-boot" target="_blank" type="primary" style="margin-top: -4px;">
                        https://gitee.com/eobard721/obfuscator-boot
                    </el-link>
                </div>
            </el-col>
        </el-row>

        <!-- 顶部路径选择 -->
        <el-row :gutter="10" style="margin-bottom: 20px;">
            <el-col :span="16">
                <!-- 改成可输入绝对路径 -->
                <el-input v-model="displayPath" placeholder="请输入绝对路径，例如 D:/Projects/SpringAI/src/main/java"></el-input>
            </el-col>
            <el-col :span="4">
                <el-button type="primary" @click="loadFolderTree">加载路径</el-button>
            </el-col>
            <el-col :span="4">
                <el-button @click="clearSelection" type="danger">清空</el-button>
            </el-col>
        </el-row>

        <!-- 文件夹列表 -->
        <el-card v-if="folders.length > 0" style="margin-bottom: 20px;">
            <div style="margin-bottom: 8px;">选择要处理的文件夹：</div>
            <folder-node v-for="folder in folders" :key="folder.path" :node="folder"
                v-model:selected="selectedFolders"></folder-node>
        </el-card>

        <div v-else style="color:#999; margin-bottom:20px;">
            还没有检测到子文件夹。请输入绝对路径并点击 “加载路径”。
        </div>

        <!-- Tabs -->
        <el-tabs v-model="activeTab" type="border-card">
            <el-tab-pane label="核心混淆功能" name="core">
                <el-form label-width="90px" size="default" style="margin-bottom: 20px;">
                    <el-form-item label="基础包名：">
                        <el-input style="width: 300px" v-model="commonBasePackage"
                            placeholder="请输入基础包名，例如 com.example" />
                    </el-form-item>
                    <el-form-item label="项目类型：">
                        <el-radio-group v-model="projectType">
                            <el-radio style="margin-right: 10px;" label="JAVA_PROJECT">Java项目</el-radio>
                            <el-radio label="ANDROID_PROJECT">安卓项目</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-form>

                <div style="color:#666;">
                    <el-collapse v-model="activeCollapses">
                        <el-collapse-item name="RenameClass">
                            <template #title>
                                <el-checkbox :model-value="selectedObfuscators.includes('RenameClass')"
                                    @change="toggleObfuscatorSelection('RenameClass', $event,1)" @click.stop
                                    style="margin-right:8px;"></el-checkbox>
                                重命名类名混淆器
                            </template>
                            <el-form label-width="200px" size="default">
                                <el-form-item label="是否只重命名被引用的类：">
                                    <el-switch v-model="renameClassConfig.renameReferencedClass" />
                                </el-form-item>
                                <el-form-item label="所选包列表：">
                                    <div>
                                        <div v-for="pkg in renameClassConfig.packageList" :key="pkg"
                                            style="display:flex; align-items:center; margin-bottom:4px;">
                                            <el-link type="primary" style="flex:1;">
                                                {{ pkg }}
                                            </el-link>
                                            <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                @click="removePackage(pkg,'renameClassConfig')">
                                                移除
                                            </el-button>
                                        </div>
                                    </div>
                                </el-form-item>
                            </el-form>
                        </el-collapse-item>

                        <el-collapse-item name="RenameMethod">
                            <template #title>
                                <el-checkbox :model-value="selectedObfuscators.includes('RenameMethod')"
                                    @change="toggleObfuscatorSelection('RenameMethod', $event,1)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                重命名方法名混淆器
                            </template>
                            <el-form label-width="200px" size="default">
                                <el-form-item label="是否只重命名被引用的方法：">
                                    <el-switch v-model="renameMethodConfig.isReferenceMethodOnly" />
                                </el-form-item>
                                <el-form-item label="所选包列表：">
                                    <div>
                                        <div v-for="pkg in renameMethodConfig.packageList" :key="pkg"
                                            style="display:flex; align-items:center; margin-bottom:4px;">
                                            <el-link type="primary" style="flex:1;">{{ pkg }}</el-link>
                                            <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                @click="removePackage(pkg,'renameMethodConfig')">
                                                移除
                                            </el-button>
                                        </div>
                                    </div>
                                </el-form-item>
                            </el-form>
                        </el-collapse-item>

                        <el-collapse-item name="RenameField">
                            <template #title>
                                <el-checkbox :model-value="selectedObfuscators.includes('RenameField')"
                                    @change="toggleObfuscatorSelection('RenameField', $event,1)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                重命名字段名混淆器
                            </template>
                            <el-form label-width="200px" size="default">
                                <el-form-item label="所选包列表：">
                                    <div>
                                        <div v-for="pkg in renameFieldConfig.packageList" :key="pkg"
                                            style="display:flex; align-items:center; margin-bottom:4px;">
                                            <el-link type="primary" style="flex:1;">{{ pkg }}</el-link>
                                            <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                @click="removePackage(pkg,'renameFieldConfig')">
                                                移除
                                            </el-button>
                                        </div>
                                    </div>
                                </el-form-item>
                            </el-form>
                        </el-collapse-item>

                        <el-collapse-item name="MethodArgument">
                            <template #title>
                                <el-checkbox :model-value="selectedObfuscators.includes('MethodArgument')"
                                    @change="toggleObfuscatorSelection('MethodArgument', $event,1)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                普通方法参数混淆器
                            </template>
                            <el-form label-width="200px" size="default">
                                <el-form-item label="是否只重命名被引用的方法：">
                                    <el-switch v-model="methodArgumentConfig.isReferenceMethodOnly" />
                                </el-form-item>
                                <el-form-item label="增加的最大参数个数：">
                                    <el-input-number v-model="methodArgumentConfig.maxAddParamNum" :min="1" :max="10" />
                                </el-form-item>
                                <el-form-item label="所选包列表：">
                                    <div>
                                        <div v-for="pkg in methodArgumentConfig.packageList" :key="pkg"
                                            style="display:flex; align-items:center; margin-bottom:4px;">
                                            <el-link type="primary" style="flex:1;">{{ pkg }}</el-link>
                                            <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                @click="removePackage(pkg,'methodArgumentConfig')">
                                                移除
                                            </el-button>
                                        </div>
                                    </div>
                                </el-form-item>
                            </el-form>
                        </el-collapse-item>

                        <el-collapse-item name="OverrideMethodArgument">
                            <template #title>
                                <el-checkbox :model-value="selectedObfuscators.includes('OverrideMethodArgument')"
                                    @change="toggleObfuscatorSelection('OverrideMethodArgument', $event,1)" @click.stop
                                    style="margin-right:8px;"></el-checkbox>
                                接口与实现类方法参数混淆器
                            </template>
                            <el-form label-width="200px" size="default">
                                <el-form-item label="增加的最大参数个数：">
                                    <el-input-number v-model="interfaceMethodArgumentConfig.maxAddParamNum" :min="1"
                                        :max="10" />
                                </el-form-item>
                            </el-form>

                        </el-collapse-item>

                        <el-collapse-item name="RandomRenamePkg">
                            <template #title>
                                <el-checkbox :model-value="selectedObfuscators.includes('RandomRenamePkg')"
                                    @change="toggleObfuscatorSelection('RandomRenamePkg', $event,1)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                随机包名重命名混淆器
                            </template>
                            <el-form label-width="200px" size="default">
                                <el-form-item label="不想重命名的包列表：">
                                    <div>
                                        <div v-for="pkg in randomRenamePkgConfig.packageList" :key="pkg"
                                            style="display:flex; align-items:center; margin-bottom:4px;">
                                            <el-link type="primary" style="flex:1;">{{ pkg }}</el-link>
                                            <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                @click="removePackage(pkg,'randomRenamePkgConfig')">
                                                移除
                                            </el-button>
                                        </div>
                                    </div>
                                </el-form-item>
                                <div
                                    style="text-align: center;margin-bottom: 4px; font-size: 14px; color: #999; background: #f5f5f5; padding: 6px 10px 6px; border-radius: 4px;">
                                    <b>💡 注意：使用这个功能之后一定要刷新页面并重新加载路径，因为文件系统的文件夹名称已经改变，如果不刷新页面进行其它混淆功能会报错
                                    </b>
                                </div>
                            </el-form>
                        </el-collapse-item>


                        <el-collapse-item name="ClassRandomShuffle">
                            <template #title>
                                <el-checkbox :model-value="selectedObfuscators.includes('ClassRandomShuffle')"
                                    @change="toggleObfuscatorSelection('ClassRandomShuffle', $event,1)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                类随机打乱混淆器
                            </template>
                            <el-form label-width="220px" size="default">
                                <el-form-item label="不想打乱类的所属包列表：">
                                    <div>
                                        <div v-for="pkg in classRandomShuffleConfig.packageList" :key="pkg"
                                            style="display:flex; align-items:center; margin-bottom:4px;">
                                            <el-link type="primary" style="flex:1;">{{ pkg }}</el-link>
                                            <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                @click="removePackage(pkg,'classRandomShuffleConfig')">
                                                移除
                                            </el-button>
                                        </div>
                                    </div>
                                </el-form-item>
                            </el-form>
                        </el-collapse-item>
                    </el-collapse>
                </div>

                <!-- 开始混淆按钮 -->
                <div style=" text-align: center;margin-top: 20px;">
                    <el-button type="primary" @click="startObfuscation">开始混淆</el-button>
                </div>
            </el-tab-pane>

            <el-tab-pane label="可选混淆功能" name="optional">
                <el-form label-width="90px" size="default" style="margin-bottom: 20px;">
                    <el-alert style="margin-top: 0px;" center effect="dark" title="该页面下的混淆功能不要同时使用！" type="success"
                        show-icon :closable="false">
                    </el-alert>
                    <el-form-item label="项目类型：" style="margin-bottom: -10px;margin-top: 10px;">
                        <el-radio-group v-model="projectType" @change="handleProjectTypeChange">
                            <el-radio style="margin-right: 10px;" label="JAVA_PROJECT">Java项目</el-radio>
                            <el-radio label="ANDROID_PROJECT">安卓项目</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-form>

                <div style="color:#666;">
                    <el-collapse v-model="activeOptionalCollapses">
                        <el-collapse-item name="MD5Obfuscator">
                            <template #title>
                                <el-checkbox :model-value="selectedOptionalObfuscators.includes('MD5Obfuscator')"
                                    @change="toggleObfuscatorSelection('MD5Obfuscator', $event,2)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                MD5混淆器
                            </template>
                            <div style="padding: 10px; color:#666;">
                                <el-form label-width="180px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="选择MD5混淆类型：">
                                        <el-radio-group v-model="md5Config.md5Type">
                                            <el-radio-button label="AUDIO">AUDIO</el-radio-button>
                                            <el-radio-button label="IMAGE">IMAGE</el-radio-button>
                                        </el-radio-group>
                                    </el-form-item>
                                </el-form>
                                <el-form label-width="180px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="所选资源文件夹：">
                                        <div>
                                            <div v-for="pkg in md5Config.packageList" :key="pkg"
                                                style="display:flex; align-items:center; margin-bottom:4px;margin-right: 25px;">
                                                <el-link type="primary" style="flex:1;">{{ pkg }}</el-link>
                                                <el-button style="margin-left: 5px;margin-top: 3px;" type="danger"
                                                    size="small" link
                                                    @click="removeOptionalPackage(pkg,'md5Config')">移除</el-button>
                                            </div>
                                        </div>
                                    </el-form-item>
                                </el-form>
                                <el-form label-width="180px" size="default">
                                    <el-form-item label="目标保存路径："></el-form-item>
                                    <el-tooltip effect="dark" content="多个路径以英文逗号隔开，eg: /xx/x, /xx/x, /xx/x"
                                        placement="top" manual
                                        :visible="activeTab === 'optional'&& activeOptionalCollapses.includes('MD5Obfuscator')">
                                        <el-input v-model="md5Config.md5TargetPath" placeholder="请输入目标保存路径"></el-input>
                                    </el-tooltip>

                                    </el-form-item>
                                    <div
                                        style="margin-bottom: 4px; font-size: 14px; color: #999; background: #f5f5f5; padding: 6px 10px 1px; border-radius: 4px;">
                                        <b>💡 注意：如果不设置目标保存路径，默认将MD5值修改后的文件保存到源路径里面；如果设置目标保存路径，设置规则：
                                            <ul style="margin-top: 1px;font-size: 12px;">
                                                <li>情况1：源文件夹数量==目标保存文件夹数量，那么修改并将源地址的文件一一对应保存到目标地址</li>
                                                <li>情况2：源文件夹数量>目标保存文件夹数量 & 目标保存文件夹数量==1，那么所有源地址的文件全部保存到目标地址</li>
                                            </ul>
                                        </b>
                                    </div>
                                </el-form>
                            </div>
                        </el-collapse-item>

                        <el-collapse-item name="RenamePackageObfuscator">
                            <template #title>
                                <el-checkbox
                                    :model-value="selectedOptionalObfuscators.includes('RenamePackageObfuscator')"
                                    @change="toggleObfuscatorSelection('RenamePackageObfuscator', $event,2)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                包移动混淆器
                            </template>
                            <div style="padding: 10px; color:#666;">
                                <el-form label-width="180px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="资源文件路径：" v-if="projectType === 'ANDROID_PROJECT'">
                                        <el-input v-model="renamePackageConfig.resourceRoot"
                                            placeholder="请输入资源文件路径，eg：/Users/eobardgu/thai_project/action-live-mix-app-android/sdk/src/main/res"></el-input>
                                    </el-form-item>
                                    <el-form-item label="是否删除旧包：">
                                        <el-radio-group v-model="renamePackageConfig.delOldFiles">
                                            <el-radio style="margin-top: 2px;margin-right: 20px;"
                                                :label="true">是</el-radio>
                                            <el-radio style="margin-top: 2px;" :label="false">否</el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                    <el-form-item label="源包名：">
                                        <div>
                                            <div v-for="pkg in renamePackageConfig.packageList" :key="pkg"
                                                style="display:flex; align-items:center; margin-bottom:4px;">
                                                <el-link type="primary" style="flex:1;">{{ pkg }}</el-link>
                                                <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                    @click="removeOptionalPackage(pkg,'renamePackageConfig')">移除</el-button>
                                            </div>
                                        </div>
                                    </el-form-item>
                                    <el-form-item label="目标包名：">
                                        <el-input v-model="renamePackageConfig.targetPackagesInput"
                                            placeholder="多个目标包名用英文逗号分隔，eg: com.xxx.a,com.xxx.b"></el-input>
                                    </el-form-item>
                                    <div
                                        style="margin-left: 96px;margin-bottom: 4px; font-size: 14px; color: #999; background: #f5f5f5; padding: 6px 10px 1px; border-radius: 4px;">
                                        <b>💡 注意：如果选择了多个源包，目标包名数量需要对应
                                            <ul style="margin-top: 1px;font-size: 12px;">其它注意
                                                <li style="color:red">目前暂不支持移动源包到已有的目标包，所以请先确保目标包是不存在的</li>
                                                <li>建议：重命名包时最好选择到子包，因为涉及到资源xml里面的很多引用修改</li>
                                                <li>建议：如果是安卓项目，混淆后务必手动检查一下资源文件的引用是否正确，eg：AndroidManifest.xml、layout文件夹、build.gradle、proguard-rules.pro等
                                                </li>
                                                <li>建议：如果是安卓项目，最好不要重命名父包(BasePackage)，因为涉及到资源xml里面的很多引用；如果实在要重命名父包，务必去检查资源xml文件的相关引用
                                                </li>
                                                <li>建议：最好不要把重命名包的功能和其它功能一起用</li>
                                            </ul>
                                        </b>
                                    </div>

                                </el-form>
                            </div>
                        </el-collapse-item>

                        <el-collapse-item name="AndroidResObfuscator">
                            <template #title>
                                <el-checkbox :model-value="selectedOptionalObfuscators.includes('AndroidResObfuscator')"
                                    @change="toggleObfuscatorSelection('AndroidResObfuscator', $event, 2)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                安卓资源文件重命名混淆器
                            </template>
                            <div style="padding: 10px; color:#666;">
                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="Java资源路径：">
                                        <el-input v-model="androidResConfig.sourceRoot"
                                            placeholder="eg：/Users/eobardgu/thai_project/action-live-mix-app-android/sdk/src/main/java"></el-input>
                                    </el-form-item>
                                </el-form>
                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="所选资源文件夹：">
                                        <div>
                                            <div v-for="dir in androidResConfig.packageList" :key="dir"
                                                style="display:flex; align-items:center; margin-bottom:4px;">
                                                <el-link type="primary" style="flex:1;">{{ dir }}</el-link>
                                                <el-button style="margin-left: 20px;" type="danger" size="small" link
                                                    @click="removeOptionalPackage(dir,'androidResConfig')">移除</el-button>
                                            </div>
                                        </div>
                                    </el-form-item>
                                </el-form>
                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item>
                                        <el-alert
                                            title="多个前缀以英文逗号隔开，例如：drawable_beak_owl , strings_beak_owl , activity_beak_owl"
                                            type="info" effect="dark" :closable="false">
                                        </el-alert>
                                    </el-form-item>
                                </el-form>
                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="资源文件旧前缀：">
                                        <el-input v-model="androidResConfig.resourceOldPrefixInput"
                                            placeholder="请输入旧前缀，多个用逗号隔开"></el-input>
                                    </el-form-item>
                                </el-form>
                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="资源文件转换后的目标前缀：">
                                        <el-input v-model="androidResConfig.resourceNewPrefixInput"
                                            placeholder="请输入新前缀，多个用逗号隔开"></el-input>
                                    </el-form-item>
                                    <div
                                        style="margin-left: 70px;margin-bottom: 4px; font-size: 14px; color: #999; background: #f5f5f5; padding: 6px 10px 1px; border-radius: 4px;">
                                        <b>💡 注意：填写资源文件夹前缀时需要遵守设置规则
                                            <ul style="margin-top: 1px;font-size: 12px;">
                                                <li>情况1：旧前缀数量==目标前缀数量，那么对应位置旧前缀会转换为目标前缀</li>
                                                <li>情况2：旧前缀数量>目标前缀数量 && 目标前缀数量==1，那么所有旧前缀会被转换为目标前缀</li>
                                            </ul>
                                        </b>
                                    </div>
                                </el-form>
                            </div>
                        </el-collapse-item>

                        <el-collapse-item name="MnnObfuscator">
                            <template #title>
                                <el-checkbox :model-value="selectedOptionalObfuscators.includes('MnnObfuscator')"
                                    @change="toggleObfuscatorSelection('MnnObfuscator', $event, 2)" @click.stop
                                    style="margin-right:8px;">
                                </el-checkbox>
                                Mnn模型转换器
                            </template>
                            <div style="padding: 10px; color:#666;">
                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item v-if="mnnConfig.forward" label="MNN模型所在路径：">
                                        <el-input v-model="mnnConfig.modelPath"
                                            placeholder="eg：/Users/eobardgu/thai_project/action-live-mix-app-android/sdk/src/main/assets/models"></el-input>
                                    </el-form-item>
                                </el-form>

                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="转换器安装方式：">
                                        <el-radio-group v-model="mnnConfig.installType">
                                            <el-radio-button label="PIP">PIP</el-radio-button>
                                            <el-radio-button label="SOURCE_CODE">SOURCE_CODE</el-radio-button>
                                        </el-radio-group>
                                    </el-form-item>
                                    <el-form-item v-if="mnnConfig.installType === 'SOURCE_CODE'" label="转换器源码安装根目录：">
                                        <el-input v-model="mnnConfig.sourceCodeInstallPath"
                                            placeholder="/Users/eobardgu/mnn_workspace/MNN"></el-input>
                                    </el-form-item>
                                </el-form>


                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="转换方式：">
                                        <el-switch v-model="mnnConfig.forward" active-text="Mnn2Json"
                                            inactive-text="Json2Mnn">
                                        </el-switch>
                                    </el-form-item>
                                </el-form>

                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item label="临时保存位置：">
                                        <el-input v-model="mnnConfig.tempPath"
                                            placeholder="模型转为json文件临时保存的位置,默认会保存到：用户工作目录/mnn_converter_output"></el-input>
                                    </el-form-item>
                                </el-form>


                                <el-form label-width="200px" size="default" style="margin-bottom: 15px;">
                                    <el-form-item v-if="mnnConfig.forward" label="指定转换的模型名称：">
                                        <el-input v-model="mnnConfig.modelNames"
                                            placeholder="指定哪些mnn文件需要转换，默认把MNN模型所在路径下所有模型都转换，多个用逗号隔开"></el-input>
                                    </el-form-item>
                                    <div
                                        style="margin-left: 70px;margin-bottom: 4px; font-size: 14px; color: #999; background: #f5f5f5; padding: 6px 10px 1px; border-radius: 4px;">
                                        <b>💡 注意：
                                            <ul style="margin-top: 1px;font-size: 12px;">
                                                <li>当执行完Mnn2Json后，你需要手动在临时保存位置中自行更改json里面的数据，实现模型的md5混淆</li>
                                                <li>当你修改完json数据后，直接执行Json2Mnn功能即可将你刚刚更改后的json文件转为最新的mnn文件</li>
                                            </ul>
                                        </b>
                                    </div>
                                </el-form>
                            </div>
                        </el-collapse-item>
                    </el-collapse>
                </div>
                <!-- 开始混淆按钮 -->
                <div style=" text-align: center;margin-top: 20px;">
                    <el-button type="primary" @click="startOptionalObfuscation">开始混淆</el-button>
                </div>
            </el-tab-pane>

        </el-tabs>


    </div>

    <script src="./js/vue.js"></script>
    <script src="./js/element.js"></script>
    <script src="./js/custom.js"></script>
    <script>
        const { createApp } = Vue;
        const { ElMessage } = ElementPlus;

        createApp({
            components: { FolderNode },
            data() {
                return {
                    displayPath: '',    //输入的项目绝对路径
                    commonBasePackage: '',  //核心混淆器里面的基础包名
                    projectType: 'JAVA_PROJECT',         //项目类型
                    folders: [],             //文件夹列表
                    selectedFolders: [],    //选中的文件夹列表有哪些
                    activeTab: 'core',      //默认选中的tabs
                    activeCollapses: [],    // 核心混淆器默认打开的折叠面板
                    activeOptionalCollapses: [],            // 可选混淆器默认打开的折叠面板
                    selectedObfuscators: [], // 记录核心混淆器面板复选框勾选的哪些折叠面板
                    selectedOptionalObfuscators: [], // 记录可选混淆器复选框勾选的哪些折叠面板
                    //重命名类名混淆器配置
                    renameClassConfig: {
                        renameReferencedClass: true, // 是否重命名引用类
                        packageList: [] // 选中的包列表
                    },
                    // 重命名字段名混淆器配置
                    renameFieldConfig: {
                        basePackage: '',  // 输入框对应的基础包名
                        packageList: []   // 选中的包列表
                    },
                    //重命名方法名混淆器配置
                    renameMethodConfig: {
                        isReferenceMethodOnly: false, // 是否只需要重命名引用的方法
                        basePackage: '',             // 输入框对应的基础包名
                        packageList: []              // 选中的包列表
                    },
                    //重命名普通方法参数混淆器配置
                    methodArgumentConfig: {
                        basePackage: '',         // 输入框对应的基础包名
                        isReferenceMethodOnly: false,    //是否只重命名被引用的方法
                        minAddParamNum: 1,          //最小增加的参数
                        maxAddParamNum: 3,          //最大增加的参数
                        packageList: []             // 选中的包列表
                    },
                    //接口与实现类方法参数的参数配置类
                    interfaceMethodArgumentConfig: {
                        basePackage: '',
                        minAddParamNum: 1,
                        maxAddParamNum: 3,
                    },
                    //随机重命名包名的参数配置类
                    randomRenamePkgConfig: {
                        basePackage: '',  // 输入框对应的基础包名
                        packageList: []             // 选中的包列表 
                    },
                    //类随机打乱混淆器参数配置类
                    classRandomShuffleConfig: {
                        basePackage: '',  // 输入框对应的基础包名
                        packageList: []             // 选中的包列表 
                    },
                    //md5混淆器的参数配置类
                    md5Config: {
                        md5Type: 'AUDIO',           // 默认类型
                        // md5PackageList: [],         // MD5 混淆器选中的文件夹列表
                        packageList: [],
                        md5TargetPath: '',          // 目标保存路径
                    },
                    //重命名包名参数配置类
                    renamePackageConfig: {
                        resourceRoot: '',               // 安卓项目资源文件路径
                        delOldFiles: false,             // 默认不删除旧包
                        // sourcePackages: [],            // 源包
                        packageList: [],
                        targetPackagesInput: ''        // 目标包
                    },
                    //安卓资源文件混淆参数配置类
                    androidResConfig: {
                        sourceRoot: "",
                        packageList: [],
                        resourceOldPrefixInput: "",
                        resourceNewPrefixInput: ""
                    },
                    //mnn模型转换参数配置类
                    mnnConfig: {
                        modelPath: "",
                        installType: "PIP",
                        sourceCodeInstallPath: "",
                        forward: true,
                        tempPath: "",
                        modelNames: ""
                    }
                };
            }, watch: {
                selectedFolders(newVal) {
                    const pkgList = newVal.map(p => p.replace(/\//g, '.'));
                    this.renameClassConfig.packageList = pkgList;
                    this.renameFieldConfig.packageList = pkgList;
                    this.randomRenamePkgConfig.packageList = pkgList;
                    this.renameMethodConfig.packageList = pkgList;
                    this.methodArgumentConfig.packageList = pkgList;
                    this.md5Config.packageList = pkgList;
                    this.renamePackageConfig.packageList = pkgList;
                    this.androidResConfig.packageList = pkgList;
                    this.classRandomShuffleConfig.packageList = pkgList;
                }
            },
            methods: {
                //加载文件夹树
                loadFolderTree() {
                    if (!this.displayPath) {
                        ElMessage.warning('请输入绝对路径');
                        return;
                    }
                    loadTree(this.displayPath, this)
                },
                //清空按钮
                clearSelection() {
                    clear(this);
                },
                //所有折叠面板的复选框按钮
                toggleObfuscatorSelection(name, checked, type) {
                    //type=1:selectedObfuscators；type=2:selectedOptionalObfuscators
                    let targetArray = type === 1 ? this.selectedObfuscators : this.selectedOptionalObfuscators;
                    if (checked) {
                        if (!targetArray.includes(name)) {
                            targetArray.push(name);
                        }
                    } else {
                        targetArray = targetArray.filter(n => n !== name);
                    }
                    if (type === 1) {
                        this.selectedObfuscators = targetArray;
                    } else {
                        this.selectedOptionalObfuscators = targetArray;
                    }
                },
                //核心混淆器中移除所选包方法
                removePackage(pkg, list) {
                    const pathFormat = pkg.replace(/\./g, '/');
                    this[list].packageList = this[list].packageList.filter(p => p !== pkg);
                    this.selectedFolders = this.selectedFolders.filter(p => !p.endsWith(pathFormat));
                },
                //核心混淆器的开始混淆按钮
                startObfuscation() {
                    if (!this.displayPath) {
                        ElMessage.error('请输入项目绝对地址!');
                        return;
                    }
                    if (!this.commonBasePackage) {
                        ElMessage.error('请输入基础包名!');
                        return;
                    }
                    if (this.selectedObfuscators.length === 0) {
                        ElMessage.error("你当前还未选择任何混淆功能");
                        return;
                    }
                    // 统一赋值到每个混淆器的 basePackage
                    this.renameFieldConfig.basePackage = this.commonBasePackage;
                    this.renameMethodConfig.basePackage = this.commonBasePackage;
                    this.methodArgumentConfig.basePackage = this.commonBasePackage;
                    this.interfaceMethodArgumentConfig.basePackage = this.commonBasePackage;
                    this.randomRenamePkgConfig.basePackage = this.commonBasePackage;
                    this.classRandomShuffleConfig.basePackage = this.commonBasePackage;
                    //传输的json数据
                    const payload = {
                        sourceRoot: this.displayPath,
                        isAndroidProject: this.projectType == 'ANDROID_PROJECT'
                    };

                    if (this.selectedObfuscators.includes('RenameClass')) {
                        payload.renameClass = {
                            referencedClassOnly: this.renameClassConfig.renameReferencedClass,
                            packageList: this.renameClassConfig.packageList
                        };
                    }

                    if (this.selectedObfuscators.includes('RenameField')) {
                        payload.renameField = {
                            basePackage: this.renameFieldConfig.basePackage,
                            packageList: this.renameFieldConfig.packageList
                        };
                    }
                    if (this.selectedObfuscators.includes('RenameMethod')) {
                        payload.renameMethod = {
                            referenceMethodOnly: this.renameMethodConfig.isReferenceMethodOnly,
                            basePackage: this.renameMethodConfig.basePackage,
                            packageList: this.renameMethodConfig.packageList
                        };
                    }
                    if (this.selectedObfuscators.includes('MethodArgument')) {
                        payload.methodArgument = {
                            basePackage: this.methodArgumentConfig.basePackage,
                            referenceMethodOnly: this.methodArgumentConfig.isReferenceMethodOnly,
                            minAddParamNum: 1,
                            maxAddParamNum: this.methodArgumentConfig.maxAddParamNum,
                            packageList: this.methodArgumentConfig.packageList
                        };
                    }

                    if (this.selectedObfuscators.includes('OverrideMethodArgument')) {
                        payload.interfaceMethodArgument = {
                            basePackage: this.interfaceMethodArgumentConfig.basePackage,
                            minAddParamNum: 1,
                            maxAddParamNum: this.interfaceMethodArgumentConfig.maxAddParamNum,
                        };
                    }
                    if (this.selectedObfuscators.includes('RandomRenamePkg')) {
                        payload.randomRenamePkgConfig = {
                            sourceRoot: this.displayPath,
                            basePackage: this.randomRenamePkgConfig.basePackage,
                            excludePackages: this.randomRenamePkgConfig.packageList,
                        };
                    }
                    if (this.selectedObfuscators.includes('ClassRandomShuffle')) {
                        payload.classRandomShuffleConfig = {
                            sourceRoot: this.displayPath,
                            basePackage: this.classRandomShuffleConfig.basePackage,
                            excludePackages: this.classRandomShuffleConfig.packageList,
                        };
                    }
                    // console.log("发送给后端的 JSON:", payload);
                    // return;
                    obfuscate(payload)
                },
                //可选混淆器中移除所选包方法
                removeOptionalPackage(pkg, list) {
                    this[list].packageList = this[list].packageList.filter(p => p !== pkg);
                    const path = pkg.replace(/\./g, '/');
                    this.selectedFolders = this.selectedFolders.filter(p => p !== path);
                },
                //可选混淆器的开始混淆按钮
                startOptionalObfuscation() {
                    if (this.selectedOptionalObfuscators.length === 0) {
                        ElMessage.error("你当前还未选择任何可选混淆功能");
                        return;
                    }
                    const payload = {
                        isAndroidProject: this.projectType == 'ANDROID_PROJECT'
                    };
                    //选中的MD5混淆器
                    if (this.selectedOptionalObfuscators.includes('MD5Obfuscator')) {
                        if (this.md5Config.packageList.length === 0) {
                            ElMessage.error("你当前还未选择任何资源文件夹");
                            return;
                        }
                        let targetDirs = [];
                        if (this.md5Config.md5TargetPath && this.md5Config.md5TargetPath.trim() !== '') {
                            targetDirs = this.md5Config.md5TargetPath
                                .split(/[,，]/)
                                .map(path => path.trim())
                                .filter(path => path.length > 0);
                        }
                        const normalizedPackages = this.md5Config.packageList.map(pkg =>
                            pkg.replace(/\./g, '/')
                        );
                        payload.resourceRoot = this.displayPath
                        payload.md5Config = {
                            audioSourceDirs: this.md5Config.md5Type === 'AUDIO' ? [...normalizedPackages] : [],
                            audioSaveTargetDirs: this.md5Config.md5Type === 'AUDIO' ? targetDirs : [],
                            imageSourceDirs: this.md5Config.md5Type === 'IMAGE' ? [...normalizedPackages] : [],
                            imageSaveTargetDirs: this.md5Config.md5Type === 'IMAGE' ? targetDirs : []
                        };
                    }
                    //选中的包名重命名混淆器
                    if (this.selectedOptionalObfuscators.includes('RenamePackageObfuscator')) {
                        let targetPackages = [];
                        if (this.renamePackageConfig.targetPackagesInput.trim() !== '') {
                            targetPackages = this.renamePackageConfig.targetPackagesInput
                                .split(/[,，]/)
                                .map(s => s.trim())
                                .filter(s => s.length > 0);
                        }
                        payload.sourceRoot = this.displayPath
                        payload.resourceRoot = this.projectType === 'ANDROID_PROJECT' ? this.renamePackageConfig.resourceRoot : null
                        payload.renamePackage = {
                            isAndroidProject: this.projectType === 'ANDROID_PROJECT',
                            delOldFiles: this.renamePackageConfig.delOldFiles,
                            sourcePackages: [...this.renamePackageConfig.packageList],
                            targetPackages
                        }
                    }
                    //选中的资源文件重命名混淆器
                    if (this.selectedOptionalObfuscators.includes("AndroidResObfuscator")) {
                        if (this.androidResConfig.sourceRoot.length === 0) {
                            ElMessage.error("你当前还未输入安卓的Java资源路径");
                            return;
                        }
                        if (this.androidResConfig.resourceOldPrefixInput.length === 0) {
                            ElMessage.error("请先输入资源文件的公共前缀");
                            return;
                        }
                        if (this.androidResConfig.resourceNewPrefixInput.length === 0) {
                            ElMessage.error("请先输入重命名后的资源文件目标前缀");
                            return;
                        }
                        payload.sourceRoot = this.androidResConfig.sourceRoot
                        payload.resourceRoot = this.displayPath
                        payload.androidResConfig = {
                            dirs: [...this.androidResConfig.packageList],
                            resourceOldPrefix: this.androidResConfig.resourceOldPrefixInput
                                .split(/[,，]/)
                                .map(s => s.trim())
                                .filter(s => s.length > 0),
                            resourceNewPrefix: this.androidResConfig.resourceNewPrefixInput
                                .split(/[,，]/)
                                .map(s => s.trim())
                                .filter(s => s.length > 0)
                        };
                    }
                    //选中的模型转换混淆器
                    if (this.selectedOptionalObfuscators.includes('MnnObfuscator')) {
                        if (this.mnnConfig.forward && this.mnnConfig.modelPath.length === 0) {
                            ElMessage.error("你当前还未输入MNN模型的根路径");
                            return;
                        }

                        if (this.mnnConfig.installType == "SOURCE_CODE") {
                            if (this.mnnConfig.sourceCodeInstallPath.length === 0) {
                                ElMessage.error("你当前还未输入转换器源码安装根目录");
                                return;
                            }
                        }
                        payload.mnnConfig = {
                            mnnModelPath: this.mnnConfig.modelPath,
                            installEnum: this.mnnConfig.installType,
                            mnnInstallRoot: this.mnnConfig.sourceCodeInstallPath,
                            forwardConverter: this.mnnConfig.forward,
                            converterPath: this.mnnConfig.tempPath,
                            mnnModelNames: this.mnnConfig.modelNames.split(/[,，]/).map(s => s.trim()).filter(s => s.length > 0)
                        }
                    }

                    // console.log(payload);
                    obfuscate(payload)
                },
                //可选混淆功能里面项目类型change事件
                handleProjectTypeChange(value) {
                    if (value === 'ANDROID_PROJECT') {
                        this.$notify({
                            title: '提示',
                            message: '当前运行项目为安卓项目，当前页面下的混淆器将会修改安卓资源文件相关引用',
                            duration: 7000
                        });
                    }
                }
            },
            mounted() {
                watermark()
            }
        }).use(ElementPlus).mount('#app');
    </script>
</body>

</html>